public class Solution1518 {
    public int numWaterBottles(int numBottles, int numExchange) {
        int rest=0,ans=0;
        while (numBottles!=0){
            ans=ans+numBottles;
            rest+=numBottles;
            numBottles=rest/numExchange;
            rest=rest%numExchange;
        }
        return ans+numBottles;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1518().numWaterBottles(15,4));
    }
}
